package org.budo.storm.jdbc.util;

import java.util.List;

import org.apache.storm.jdbc.common.Column;
import org.budo.support.lang.util.StringUtil;

import lombok.extern.slf4j.Slf4j;

/**
 * @author lmw
 */
@Slf4j
public class StormJdbcUtil {
    public static Object getValueByName(List<Column> columns, String columnName) {
        if (null == columns) {
            log.error("#16 columns=" + columns + ", columnName=" + columnName);
            return null;
        }

        if (null == columnName) {
            log.error("#20 columnName=" + columnName + ", columns=" + columns);
            return null;
        }

        for (Column column : columns) {
            if (null == column) {
                log.error("#28 column=" + column);
                continue;
            }

            String name = column.getColumnName();
            if (StringUtil.equals(name, columnName)) {
                Object val = column.getVal();
                if (null != val) {
                    return val;
                }

                log.error("#39 val is null, name=" + name);
                return null;
            }
        }

        log.error("#44 return null, columnName=" + columnName);
        return null;
    }
}